package com.wisemoresystem.seal.action.wk;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wisemoresystem.seal.base.action.ProjBaseAction;
import com.wisemoresystem.seal.base.tip.Tip;
import com.wisemoresystem.seal.model.t_wkflow;
import com.wisemoresystem.seal.service.JobService;
import com.wisemoresystem.seal.service.WkflowService;
import com.wisemoresystem.seal.web.WebTools;

/**
 * 工作流管理
 * 
 * @author Administrator
 *
 */
@Controller("ixWkflowAction")
@Scope("prototype")
@RequestMapping("/ix/wkflow")
public class WkflowAction extends ProjBaseAction {

	@Autowired
	private WkflowService wkService;
	@Autowired
	private JobService lService;

	@RequestMapping("/list")
	public ModelAndView list(String srh_reason, String srh_user) {

		List<Map<String, Object>> list = wkService.selectWkflowList();

		ModelAndView mv = new ModelAndView("/jsp/wkflow/list");
		mv.addObject("list", list);
		return mv;
	}

	@RequestMapping("/add_form")
	public ModelAndView add_form() {
		List<Map<String, Object>> jobList = lService.selectJobList();

		ModelAndView mv = new ModelAndView("/jsp/wkflow/add_form");
		mv.addObject("jobList", jobList);
		return mv;
	}

	@RequestMapping("/add")
	public ModelAndView add(t_wkflow wkflow) {
		wkflow.setBank_id(WebTools.getCurrentBankId());
		oc.saveObj(wkflow);

		this.setTipMsg("保存成功", Tip.Type.success);
		ModelAndView mv = new ModelAndView("redirect:list.htm");
		return mv;
	}

	@RequestMapping("/edit_form")
	public ModelAndView edit_form(String wkflow_id) {
		List<Map<String, Object>> jobList = lService.selectJobList();
		t_wkflow wkflow = oc.findObjById(wkflow_id, t_wkflow.class);

		ModelAndView mv = new ModelAndView("/jsp/wkflow/edit_form");
		mv.addObject("jobList", jobList);
		mv.addObject("wkflow", wkflow);
		return mv;
	}

	@RequestMapping("/edit")
	public ModelAndView edit(String wkflow_id, t_wkflow wkflow) {
		t_wkflow wkflowDb = oc.findObjById(wkflow_id, t_wkflow.class);
		wkflowDb.setJob_codes(wkflow.getJob_codes());
		wkflowDb.setName(wkflow.getName());
		wkflowDb.setNote(wkflow.getNote());
		oc.updateObj(wkflowDb);

		this.setTipMsg("保存成功", Tip.Type.success);
		ModelAndView mv = new ModelAndView("redirect:list.htm");
		return mv;
	}

	@RequestMapping("/del")
	public ModelAndView del(String wkflow_id) {

		oc.delObjById(wkflow_id, t_wkflow.class);

		super.setTipMsg("操作成功！", Tip.Type.success);
		ModelAndView mv = new ModelAndView("redirect:list.htm");
		return mv;
	}
}
